Skip to content

Fix #12: Add gateway contract test suite across providers#17

Open
WarLikeLaux wants to merge 2 commits into
yiisoft:masterfrom
WarLikeLaux:add-GatewayContractTest
Open

Fix #12: Add gateway contract test suite across providers#17
WarLikeLaux wants to merge 2 commits into
yiisoft:masterfrom
WarLikeLaux:add-GatewayContractTest

Conversation

@WarLikeLaux
Copy link
Copy Markdown

@WarLikeLaux WarLikeLaux commented Jun 1, 2026

Q A
Is bugfix?
New feature?
Tests added? ✔️
Breaks BC?
Fixed issues #12

What does this PR do?

Adds a shared gateway contract test suite that runs one set of assertions against every gateway through PaymentGatewayInterface, proving a provider can be swapped without changing caller code.

An abstract GatewayContractTestCase holds the assertions; the Stripe, PayPal, Robokassa and YooKassa subclasses supply only a gateway factory, canned HTTP responses and expected values. Existing per-provider tests stay - they cover request encoding, which the contract suite does not.

Changelog not required, because no source files changed.

Summary by CodeRabbit

Tests

  • Added comprehensive contract tests for payment gateway implementations (PayPal, Stripe, YooKassa, Robokassa) validating payment intent creation and retrieval, refund processing with amount verification, customer management, and currency normalization to ensure consistent behavior across all supported gateways.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.46%. Comparing base (f8fee9d) to head (a364adb).

Additional details and impacted files
@@             Coverage Diff              @@
##             master      #17      +/-   ##
============================================
+ Coverage     73.74%   75.46%   +1.72%     
  Complexity      573      573              
============================================
  Files            52       52              
  Lines          2030     2030              
============================================
+ Hits           1497     1532      +35     
+ Misses          533      498      -35     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@WarLikeLaux
Copy link
Copy Markdown
Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6283d4e1-7bce-4387-9796-d3dc9508675a

📥 Commits

Reviewing files that changed from the base of the PR and between f8fee9d and c187621.

📒 Files selected for processing (6)
  • tests/Gateways/Contract/GatewayContractTestCase.php
  • tests/Gateways/Contract/IntentExpectation.php
  • tests/Gateways/Contract/PayPalGatewayContractTest.php
  • tests/Gateways/Contract/RobokassaGatewayContractTest.php
  • tests/Gateways/Contract/StripeGatewayContractTest.php
  • tests/Gateways/Contract/YooKassaGatewayContractTest.php

📝 Walkthrough

Walkthrough

This PR introduces a reusable contract-testing framework for payment gateways. It adds an abstract base class that defines the contract tests themselves, plus concrete implementations for four gateways (PayPal, Robokassa, Stripe, YooKassa). Each gateway implementation provides fixtures that configure the gateway, queue HTTP responses, and define expected result shapes.

Changes

Gateway Contract Testing Framework

Layer / File(s) Summary
Intent expectation value object
tests/Gateways/Contract/IntentExpectation.php
Introduces IntentExpectation, a readonly value object that captures the normalized intent properties (id, amount, currency, status) expected by contract tests.
Gateway contract testing base class
tests/Gateways/Contract/GatewayContractTestCase.php
Defines GatewayContractTestCase abstract base class with test infrastructure (PSR-17 factory, HTTP client setup) and concrete contract test methods (testCreatePaymentIntentReturnsNormalizedIntent, testCreatePaymentIntentNormalizesCurrencyToUpperCaseIso, testRetrievePaymentIntentReturnsRequestedIntent, testCreateRefundReturnsNonEmptyResult, testCreateCustomerPreservesIdentity, testCreateCustomerAssignsRemoteIdWhenSupported). Declares abstract fixture methods for gateway creation and test data provisioning.
Gateway contract test implementations
tests/Gateways/Contract/PayPalGatewayContractTest.php, tests/Gateways/Contract/RobokassaGatewayContractTest.php, tests/Gateways/Contract/StripeGatewayContractTest.php, tests/Gateways/Contract/YooKassaGatewayContractTest.php
Implements contract test fixtures for PayPal, Robokassa, Stripe, and YooKassa gateways. Each test class instantiates its gateway with test credentials, queues deterministic HTTP responses for payment intent creation/retrieval, refund handling, and customer creation; defines fixture data builders and response shape assertions.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops through gateways four,
With contracts sealed, each test to score,
Intent expectations mapped just right,
PayPal, Stripe, and Robokassa bright,
YooKassa too—all contracts ignite! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.90% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a gateway contract test suite across payment providers (Stripe, PayPal, Robokassa, YooKassa).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.2.1)

PHP Parse error: syntax error, unexpected token "->", expecting ";" in /vendor/php-standard-library/php-standard-library/packages/class/src/Psl/Class/has_constant.php on line 18
Parse error: syntax error, unexpected token "->", expecting ";" in /vendor/php-standard-library/php-standard-library/packages/class/src/Psl/Class/has_constant.php on line 18


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@WarLikeLaux
Copy link
Copy Markdown
Author

Heads-up from writing the suite: intents are genuinely interchangeable (the PaymentIntent model normalizes currency/amount), but createRefund isn't - it returns raw provider arrays with different keys (Robokassa has no id, PayPal's amount is nested, Stripe/YooKassa differ on created/created_at), so the suite only checks "non-empty array" universally and the concrete shape per subclass. A Refund model would fix that. Also retrievePaymentIntent leaves amount/currency null on Robokassa's XML path.

Want these as separate follow-up issues? @mob-stuv @samdark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant